//
//  Date+Extension.swift
//  SwiftProject
//
//  Created by qindong on 2021/3/12.
//

import Foundation

extension Date {
    // MARK: - 快捷方法 获取date的信息
    func getDateComponent(_ component : Calendar.Component) -> Int {
        let calendar : Calendar = .current
        let components : DateComponents = calendar.dateComponents([component], from: self)
        switch component {
        case .day:
            return components.day!
        case .hour:
            return components.hour!
        case .minute:
            return components.minute!
        case .month:
            return components.month!
        case .second:
            return components.second!
        case .year:
            return components.year!
        case .weekday:
            return components.weekday!
        case .nanosecond:
            return components.nanosecond!
        default:
            return 0
        }
    }

    var weekdayStr : String {
        switch getDateComponent(.weekday) {
        case 1:
            return "星期天"
        case 2:
            return "星期一"
        case 3:
            return "星期二"
        case 4:
            return "星期三"
        case 5:
            return "星期四"
        case 6:
            return "星期五"
        case 7:
            return "星期六"
        default:
            return ""
        }
    }
}

